<template>
	<view class="wanlshop-category-container">
		<!-- 导航条 -->
		<view class="cu-custom" :style="{ height: $wanlshop.wanlsys().height + 'px' }">
			<view class="cu-bar fixed bg-white solid-bottom" :style="{
					height: $wanlshop.wanlsys().height + 'px',
					paddingTop: $wanlshop.wanlsys().top + 'px'
				}">
				<view class="flex justify-between align-center">
					<view class="action" @tap="$wanlshop.back(1)">
						<text class="wlIcon-fanhui1"></text>
					</view>
					<view class="contents text-xl text-bold margin-left-xs" :style="{top: $wanlshop.wanlsys().top + 'px'}" @tap="$wanlshop.to('/pages/page/city')">
						<text>医护上门 · {{common.addressText}}</text>
						<text style="margin-top: 14rpx;font-size: 22rpx;" class="wlIcon-jiang margin-top"></text>
					</view>
				</view>
				<!-- #ifndef MP -->
				<view class="action" @tap="showModal('menu')">
					<text class="wlIcon-gengduo"></text>
					<view class="cu-tag badge bg-green" v-if=" statistics.notice.notice + statistics.notice.order + statistics.notice.chat + statistics.order.pay + statistics.order.delive + statistics.order.receiving + statistics.order.evaluate + cart.cartnum > 0 "></view>
				</view>
				<!-- #endif -->
			</view>
		</view>
		<!-- 加载类目 -->
		<wanl-classify :mainHeight="height" :categoryStyle="4" :categoryData="categoryModules" :goodsList="dataList" @getGoods="getProduct" />
		<!-- 模态框 -->
		<view class="WANL-MODAL">
			<view class="cu-modal top-modal" :class="modalName == 'menu' ? 'show' : ''" @tap="hideModal">
				<view class="wanl-modal-menu cu-dialog" @tap.stop="">
					<wanl-directs @change="modalName = null" :top="$wanlshop.wanlsys().height"/>
				</view>
			</view>
			<!-- 分享 -->
			<view class="cu-modal bottom-modal" :class="modalName == 'share' ? 'show' : ''" @tap="hideModal">
				<view class="cu-dialog" @tap.stop="">
					<wanl-share :scrollAnimation="scrollAnimation" shareTitle="我发现了一个很好的线上购物商城，这是商城类目"
						shareText="品质好而且很省钱如果自己在上面购买，每年可以省下1%~40%的钱" :image="$wanlshop.appstc('/common/logo.png')"
						:href="common.appConfig.domain + '/pages/category?QRtype=category'" @change="hideModal" />
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				height: 0,
				modalName: null,
				scrollAnimation: 300,
				
				categoryModules: [],
				page:1,
				order:'',
				dataList:[]
			};
		},
		computed: {
			...mapState(['common', 'statistics', 'cart'])
		},
		onLoad() {
			let wanlsys = this.$wanlshop.wanlsys();
			// #ifdef APP-PLUS
			this.height = wanlsys.windowHeight  - wanlsys.height;
			// #endif
			// #ifdef H5
			this.height = wanlsys.windowHeight - wanlsys.height;
			// #endif
			// #ifdef MP
			this.height = wanlsys.windowHeight - wanlsys.height;
			// #endif
			// #ifdef MP-WEIXIN
			wx.showShareMenu({
				withShareTicket: true,
				menus: ['shareAppMessage', 'shareTimeline']
			});
			// #endif
			this.loadData()
		},
		methods: {
			// 异步加载
			async loadData() {
				await uni.request({
					url: `/addons/medicalvisit/api.Category/index`,
					method: 'POST',
					data:{
						type:'list'
					},
					success: res => {
						this.categoryModules = res.data
						this.getProduct(res.data[0].id)
					}
				})
				// await uni.request({
				// 	url: '/publics/category/lists',
				// 	data: {
				// 		type: "shops"
				// 	},
				// 	success: res => {
				// 		this.categoryModules = res.data
				// 	}
				// });
			},
			async getProduct(category_id) {
				this.category_id = category_id
				let that = this
				await uni.request({
					url: `${this.$config.vehicleurl}/addons/medicalvisit/api.Product/list`,
					method: 'POST',
					data:{
						type:'list',
						city_id: uni.getStorageSync("cityid"),
						page:this.page,
						category_id:category_id,
						order: this.order
					},
					success: res => {
						that.dataList = res.data.data;
					}
				});
			},
			// 弹出层
			showModal(name) {
				// 滚动下分享
				if (name == 'share' && this.modalName != 'share') {
					setTimeout(() => {
						this.scrollAnimation = 300;
					}, 300);
				}
				this.modalName = name;
			},
			hideModal(name) {
				if (name) {
					this.showModal(name);
				} else {
					this.modalName = null;
				}
			}
		}
	};
</script>

<style>
	.cu-custom .cu-bar {
		z-index: 99;
	}

	.cu-bar .action {
		position: relative;
	}

	/* #ifdef MP */
	.cu-bar .search-form {
		margin: 0 0 0 25rpx;
	}

	/* #endif */
</style>